package Text24;

import java.util.*;

public class Main {
    static int[] months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int y = in.nextInt();
        int t = in.nextInt();
        int m = 1;
        while (true) {
            if(t>get_months_days(y,m)){
                t-=get_months_days(y,m);
                m++;
            }else {
                break;
            }
        }
        System.out.println(m);
        System.out.println(t);
    }

    private static int is_leap(int y) {
        if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) {
            return 1;
        }
        return 0;
    }

    private static int get_months_days(int y, int m) {
        if (m == 2) {
            return months[m] + is_leap(y);
        }
        return months[m];
    }
}
